package com.perfma.xtest.tool.word;

import java.io.Serializable;

/**
 * @author: junhui.si
 * @date: 2020-11-16 16:50
 **/
public class Pair<A, B> implements Serializable {
    private static final long serialVersionUID = -1686731431280597254L;
    private A left;
    private B right;

    public Pair(A left, B right) {
        this.left = left;
        this.right = right;
    }

    public Pair() {
    }

    public A getLeft() {
        return this.left;
    }

    public void setLeft(A left) {
        this.left = left;
    }

    public B getRight() {
        return this.right;
    }

    public void setRight(B right) {
        this.right = right;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("Pair{");
        sb.append("left=").append(this.left);
        sb.append(", right=").append(this.right);
        sb.append('}');
        return sb.toString();
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (!(o instanceof Pair)) {
            return false;
        } else {
            Pair pair = (Pair)o;
            if (this.left != null) {
                if (this.left.equals(pair.left)) {
                    return this.right != null ? this.right.equals(pair.right) : pair.right == null;
                }
            } else if (pair.left == null) {
                return this.right != null ? this.right.equals(pair.right) : pair.right == null;
            }

            return false;
        }
    }

    public int hashCode() {
        int result = this.left != null ? this.left.hashCode() : 0;
        result = 31 * result + (this.right != null ? this.right.hashCode() : 0);
        return result;
    }
}
